package com.zf.transaction.controller;

import com.zf.transaction.entity.Student;
import com.zf.transaction.service.TransactionTestService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * TransactionTestController
 */
@RequestMapping("/ttc")
@RestController
public class TransactionTestController {

    @Resource
    private TransactionTestService transactionTestService;

    @GetMapping("/selfInvoke")
    public Student selfInvoke() throws Exception {
        return transactionTestService.selfInvoke();
    }

    /**
     * 声明式事务测试
     */
    @GetMapping("/declareTransaction")
    public Student declareTransactionTest() throws Exception {
        return transactionTestService.declareTransactionTest();
    }

    /**
     * 使用 TransactionTemplate 完成编程式事务
     */
    @GetMapping("/programTransByTransactionTemplate")
    public Student programTransactionByTransactionTemplate() {
        return transactionTestService.programTransactionByTransactionTemplate();
    }

    /**
     * 使用 PlatformTransactionManager 完成编程式事务
     */
    @GetMapping("/programTransactionByPlatformTransactionManager")
    public Student programTransactionByPlatformTransactionManager() {
        return transactionTestService.programTransactionByPlatformTransactionManager();
    }

}
